package com.gome.han.bigdata.mr._002_02_wordcount;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.CombineTextInputFormat;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
* @author hanpeng
* @version 创建时间：2020年11月22日 上午11:03:02
* @ClassName 类名称
* @Description 类描述
*/
public class WordcountDriverSource {
	public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
		Configuration conf = new Configuration();
		//1,获取一个job对象
		Job job = Job.getInstance(conf);
		//2,设置jar 路径
		job.setJarByClass(WordcountDriverSource.class);
		//3,设置map和reducer的class
		job.setMapperClass(WordcountMapperSource.class);
        job.setReducerClass(WordcountReducerSource.class);
        //4 设置mapper 输出key value 的类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        //5,设置最终的输出的key和value的类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        //6,设置输出和输入的路径
       FileInputFormat.setInputPaths(job, new Path("E:/input"));
       FileOutputFormat.setOutputPath(job, new Path("E:/output"));;
       job.setInputFormatClass(CombineTextInputFormat.class);
       CombineTextInputFormat.setMaxInputSplitSize(job, 20971520);
       job.setNumReduceTasks(2);
        System.out.print("fdsf");
       boolean result = job.waitForCompletion(true);
       System.exit(result?0:1);
	}
}
